//
//  MYNoDataView.m
//  PetExchange
//
//  Created by a on 2021/3/13.
//

#import "MYNoDataView.h"

@interface MYNoDataView ()

@end

@implementation MYNoDataView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    _nodataImage = [[MyImageView alloc] init];
    [self addSubview:_nodataImage];
    [_nodataImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    _tipLabel = [[UILabel alloc] init];
    _tipLabel.font = MY_SCALE_RegularFONT(14);
    _tipLabel.textColor = MyColor(@"#cacaca");
    _tipLabel.numberOfLines = 2;
    _tipLabel.textAlignment = NSTextAlignmentCenter;
    _tipLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self addSubview:_tipLabel];
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nodataImage.mas_bottom).offset(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.centerX.equalTo(_nodataImage);
    }];
    
    _optionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _optionBtn.backgroundColor = MYRed;
    _optionBtn.layer.cornerRadius = 20;
    _optionBtn.clipsToBounds = YES;
    [_optionBtn setTitle:@"刷新" forState:UIControlStateNormal];
    [_optionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _optionBtn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [_optionBtn addTarget:self action:@selector(optionBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_optionBtn];
    _optionBtn.hidden = YES;
    [_optionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_tipLabel.mas_bottom).offset(10);
        make.centerX.equalTo(_tipLabel);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(120);
    }];
}

- (void)optionBtnClick {
    if (self.optionBtnBlock) {
        self.optionBtnBlock();
    }
}

- (void)setNormal {
    //_nodataImage.top = MY_SCALE_WIDTH(120);
//    _tipLabel.top = _nodataImage.bottom+MY_SCALE_HEIGHT(20);
//    _optionBtn.top = _tipLabel.bottom+MY_SCALE_HEIGHT(30);
//    _optionBtn.hidden = true;
}

- (void)haveOptionBtnWithText:(NSString *)txt; {
//    _optionBtn.hidden = false;
//    [_optionBtn setTitle:txt forState:UIControlStateNormal];
    
}

- (void)setHaveHeaderView:(CGFloat)headerH {
//    self.backgroundColor = [UIColor whiteColor];
    
//    if (headerH > MY_Screen_H/2) {
//        _nodataImage.top = MY_SCALE_WIDTH(30)+headerH;
//    }else {
//        _nodataImage.top = MY_SCALE_WIDTH(100)+headerH;
//    }
    
//    _nodataImage.top = 0;
//
//    _tipLabel.top = _nodataImage.bottom+MY_SCALE_HEIGHT(20);
//    _optionBtn.top = _tipLabel.bottom+MY_SCALE_HEIGHT(20);
//    _optionBtn.hidden = true;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
